package cur.channel.server;

import cur.channel.server.netty.NettyClientMap;
import cur.channel.server.netty.NettyManager;
import cur.channel.server.netty.NettyServiceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by gantianxing on 2017/7/20.
 */
@RestController
@RequestMapping("/server")
public class ServerController {
    @Autowired
    private NettyServiceUtil nettyServer;

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public Object home() {
        long start = System.currentTimeMillis();
        Map<String,Object> resMap = new HashMap<>();
        resMap.put("aa", "bbbbbbbbbbbb");
        System.out.println("time : "+(System.currentTimeMillis()-start));
        return resMap;
    }

    @RequestMapping(value = "/client", method = RequestMethod.GET)
    public Object client(){
        Collection<Map<String, NettyManager.NettyEntity>> clientVoMap = NettyClientMap.getAllClients();
        return clientVoMap;
    }

    @GetMapping(value = "/send")
    public Object send(){
        nettyServer.send("----wujian: ");
        Map<String,Object> resMap = new HashMap<>();
        resMap.put("aa", "bbbbbbbbbbbb");
        return resMap;
    }
}
